/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.core.commands;

import java.util.List;

import org.eclipse.gef.commands.Command;

import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

/**
 * 
 * 
 * @author Patrick Tessier
 * 3/03/2006
 * this command is used to delete a Graphic element from a layout
 */

public class OrphanFeatureChildCommand
	extends Command
{

/**
 * 
 */
private GraphNode parent; //graphNode for list of Features

/**
 * 
 */
private GraphNode gparent;// GraphNode for a class

/**
 * 
 */
private GraphNode child;

/**
 * 
 */
private int index;


/**
 * 
 */
public OrphanFeatureChildCommand () {
	super("orphanCommand");
	
}

/**
 * 
 */
@Override
public void execute() {
	//Manager.getRessourceManager().toConnect(gparent, child);
	List children = parent.getContained();
	index = children.indexOf(child);
	parent.getContained().remove(child);
}

/**
 * 
 */
@Override
public void redo() {
	parent.getContained().remove(child);
}

/**
 * 
 * 
 * @param child 
 */
public void setChild(GraphNode child) {
	this.child = child;
}

/**
 * 
 * 
 * @param parent 
 */
public void setParent(GraphNode parent) { 
	this.parent = parent;
	
	gparent=(GraphNode)parent.getContainer();
	
}

/**
 * 
 */
@Override
public void undo() {	
	parent.getContained().add(index, child);
}

}
